<template>
	<u-navbar :title="title" :is-back="isBack" :back-icon-name="state.isCanBack ? 'nav-back	' : 'home'" :custom-back="customBack"></u-navbar>
</template>

<script setup lang="ts" name="hx-navbar">
import { reactive, onMounted } from 'vue';
defineProps({
	title: {
		type: String,
		default: '',
	},
	isBack: {
		type: Boolean,
		default: true,
	},
});

onMounted(() => {
	const pages = getCurrentPages();
	/**
	 * 判断是否能返回
	 */
	if (pages.length <= 1 || pages[pages.length - 1].route == 'pages/login/index') {
		state.isCanBack = false;
	} else {
		state.isCanBack = true;
	}
});
const state = reactive({
	isCanBack: false,
});
const customBack = () => {
	if (state.isCanBack) {
		uni.navigateBack({
			delta: 1,
		});
	} else {
		uni.$hxRouter.push({
			type: 'switchTab',
			url: '/pages/home/index',
		});
	}
};
</script>

<style></style>
